package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//订单模块
@RestController
@RequestMapping("/order")
public class OrderController {

    //注入service
    @Autowired
    private OrderService orderService;

    //用户下单,生成订单
    @PostMapping("/submit")
    public ResultInfo submit(@RequestBody Order order){ //接收参数
        //调用service生成订单
        orderService.submit(order);
        //返回结果
        return ResultInfo.success();
    }
    //分页查询订单
    @GetMapping("/userPage")
    public ResultInfo findByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize
    ) {
        Page<Order> page = orderService.findByPage2(pageNum, pageSize);
        return ResultInfo.success(page);
    }
}
